{% extends "./inc/base.html" %}
{% block style%}
<link rel="stylesheet" href="/static/admin/js/datepicker/bootstrap-datetimepicker.min.css" type="text/css">
{% endblock %}
{% block content %}
    <section class="hbox stretch">
    <section class="vbox">
        <header class="header bg-light dk">

            <p>管理用户</p>
        </header>
        <section class="scrollable wrapper">

            <section class="panel panel-default">
                <header class="panel-heading clearfix">
                    <ul class="nav nav-tabs pull-left">
                        <li {%if status==1%} class="active" {%endif%}><a href="/admin/userqx/index/?status=1">用户列表</a></li>
                        <li {%if status==0%} class="active" {%endif%}><a href="/admin/userqx/index/?status=0">停用列表</a></li>
                    </ul>
                </header>
                <div class="row wrapper">

                    <div class="col-sm m-b-xs">
                        <div class="">
                            <a href="/admin/userqx/adduser" class="btn btn-sm btn-info " data-toggle="ajaxModal">添加用户</a>
                        </div>
                    </div>
                </div>
                    <div class="input-group pull-left search-form">
                        <input  type="hidden"  name="status"  value="{{controller.get('status') or 1}}">
                        <a >用户ID&nbsp&nbsp</a><input  type="text"  name="id"><a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</a>
                        <a >用户姓名&nbsp&nbsp</a><input  type="text" name="name"><a>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</a>
                        <a >所属核心企业&nbsp&nbsp</a>
                        <select class=" input-sm " name="zzjg" >
                            <option style='display: none'></option>
                            {%for v in zzjg%}
                            <option value="{{v.id}}">{{v.zzjg}}</option>
                            {%endfor%}
                        </select>
                        <span class="input-group-btn" >
                            <button class="btn btn-sm btn-default" type="button" id="search" url="/admin/userqx/index">搜索</button>
                            <button class="btn btn-sm btn-btn-sm" type="button" id="exportCSV" url="/admin/userqx/export"><i class="fa fa-download"></i>导出列表</button>
                        </span>
                    </div>
                <div class="table-responsive">
                    <table class="table table-striped b-t b-light">
                        <thead>
                        <tr>
                            <th style="width:20px;"><label class="checkbox m-n i-checks"><input type="checkbox"><i></i></label></th>
                            <th >用户ID</th>
                            <!--<th class="">用户名</th>-->
                            <th class="">用户姓名</th>
                            <th class="">所属核心企业</th>
                            <th class="">管理组</th>
                            <th class="">创建时间</th>
                            {%if sts==0%}
                            <th class="">停用时间</th>
                            {%endif%}
                            <th >操作</th>
                            <th >备注</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for item in list %}
                        {%set roleid=item.id|get_member_role%}
                        <tr>
                            <td><label class="checkbox m-n i-checks"><input class="ids" type="checkbox" name="ids" value="{%if item.id|in_Array(controller.config('user_administrator'))%}{%else%}{{item.id}}{%endif%}" {%if item.id|in_Array(controller.config('user_administrator'))%}disabled="true"{%endif%}><i></i></label></td>
                            <td>{{item.id}}</td>
                            <td>{{item.username}}</td>
                            <td>{{item.zzjg|get_zzjg}}</td>
                            <td>{{roleid.desc}}</td>
                            <td>{{item.reg_time | moment('YYYY-MM-DD HH:mm:ss')}}</td>
                            {%if sts==0%}
                            <td>{{item.locked_time | moment('YYYY-MM-DD HH:mm:ss')}}</td>
                            {%endif%}
                            <td>
                                {%if status==1%}
                                <a href="/admin/userqx/edituser/?id={{item.id}}" class="text-info" data-toggle="ajaxModal">编辑</a>
                                {%endif%}
                                {%if status==1%}
                                {%if item.id|in_Array(controller.config('user_administrator'))%}{%else%}
                                <a href="/admin/userqx/userdel/?ids={{item.id}}" class="confirm ajax-get text-info">停用</a>
                                {%endif%}
                                {%else%}
                                <a class="text-info ajax-post" href="/admin/user/setstatus/?status=1&model=member"  target-form="ids">
                                    启用
                                </a>
                                {%endif%}
                            </td>
                            <td><a href="/admin/userqx/remark/?id={{item.id}}" class="text-info" data-toggle="ajaxModal">新增</a>
                                <a href="/admin/order/viewremarks/?id={{item.id}}&model_name={{controller.tactive}}" class="text-info" data-toggle="ajaxModal">查看</a>
                            </td>
                        </tr>
                        {% else %}
                        <tr><td colspan="7"><div class="alert alert-warning alert-block">
                            <button data-dismiss="alert" class="close" type="button">×</button>
                            <p>暂无数据</p>
                        </div></td></tr>

                        {% endfor %}


                        </tbody>
                    </table>
                </div>
                <footer class="panel-footer">
                    <div class="row">


                        <div class="col-sm-12 text-right text-center-xs">
                            {{pagerData | safe}}
                        </div>
                    </div>
                </footer>
            </section>
        </section>
    </section>
    </section>
{% endblock%}

{% block script%}
<script src="/static/admin/js/parsley/parsley.min.js"></script>
<script src="/static/admin/js/parsley/parsley.extend.js"></script>
<script src="/static/admin/js/datepicker/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
<script src="/static/admin/js/datepicker/locales/bootstrap-datetimepicker.zh-CN.js" type="text/javascript"></script>
<script>
$(function () {

    function isPriceNumber(_keyword){
        if(_keyword == "0" || _keyword == "0." || _keyword == "0.0" || _keyword == "0.00"){
            _keyword = "0"; return true;
        }else{
            var index = _keyword.indexOf("0");
            var length = _keyword.length;
            if(index == 0 && length>1){/*0开头的数字串*/
                var reg = /^[0]{1}[.]{1}[0-9]{1,2}$/;
                if(!reg.test(_keyword)){
                    return false;
                }else{
                    return true;
                }
            }else{/*非0开头的数字*/
                var reg = /^[1-9]{1}[0-9]{0,10}[.]{0,1}[0-9]{0,2}$/;
                if(!reg.test(_keyword)){
                    return false;
                }else{
                    return true;
                }
            }
            return false;
        }
    }
    $(document).on('click', ".recharge", function (e) {
        var balance = $("input[name='balance']").val();
        var name = $("input[name = 'name']").val();
        var id = $("input[name = 'id']").val();
        if(!isPriceNumber(balance)){
            swal( "请填写正确的价格.");
            return false;
        }
        swal({
            title: "确认您的操作！",
            text: "您将给 "+name+" 充值 "+balance+" 元！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定充值!",
            cancelButtonText: "关闭!",
            closeOnConfirm: false
        }, function () {
            $.ajax({
                url:"/admin/user/recharge",
                data:{balance:balance,id:id},
                type:"POST",
                success:function (res) {
                    if(res.errno == 0){
                        swal(res.data.name, "", "success");
                        $('#ajaxModal').modal('hide');
                        location.reload();
                    }

                }
            })

        });
    })
    //搜索功能
    $("#search").click(function(){
        var url = $(this).attr('url');
        var query  = $('.search-form').find('input,select').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
        window.location.href = url;
    });

  $("#exportCSV").click(function(){
    var url = $(this).attr('url');
    var query  = $('.search-form').find('input,select').serialize();
    query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
    query = query.replace(/^&/g,'');
    if( url.indexOf('?')>0 ){
      url += '&' + query;
    }else{
      url += '?' + query;
    }
    window.location.href = url;
    //window.open("/admin/userqx/export")
  });

    //回车自动提交
    $('.search-form').find('input').keyup(function(event){
        if(event.keyCode===13){
            $("#search").click();
        }
    });

  $("input[name='istable']").on("change",function () {
    var val = $(this).val();
    console.log(val);
    if(val == 1){
      $(".tingyong").addClass('hide');
    }else {
      $(".tingyong").removeClass('hide');
    }
  })

})
</script>
{% endblock %}
